- /* sdmrefrm.cpp by K.Tsuru */
- // fuction ID = 314 DRADIX, BRADIX
- /***************************************************************************
- SDouble and SDecimal classes
- It reforms int an appropriate form considering the present operation mode
- (fixed or floating point mode).
- It adjusts the size of figure[] and removes lower zeros.
- **************************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- void SDouble::Reform(int id){
- if(abs(rdxExp) > DRADIX_EXP_MAX) SetError(TOO_LARGE_EXP,"SD",id);
- if(SNSign() == 0){
- if(!IsPointFixed()) DoCutDown(); //cutting down lower zeros
- return;
- }
- uint cms = CurrentMaxSize();
- if(Type() == BIN_DEC){
- #ifndef NDEBUG
- assert(rdxExp == 0);
- #endif
- if(aHead < cms) return;
- figure.clear(cms); //cutting down over figures
- while( !figure[aHead] && (aHead > aTail)) aHead--;
- if( (aHead == aTail) && !figure[aHead]) SetSign(0);
- return;
- }
- /*
- SDouble variable here
- When figure[0]>0 by carry, in either mode it makes figure[0]=0 by the moving
- figures.
- */
- int f = (int)aTail; //top position
- int m; //the quantity of moving figures
- // f+m : top position after moving figures
- if( IsPointFixed() ){ //fixed point mode
- /*
- The quantity of moving figures in the fixed point mode is evaluated as
- x*R^e = x*R^(e-fe)*R^(fe) = {x*R^(-m)}*R^(fe)
- m = fe - e
- */
- m = fixedExp - rdxExp;
- if(f + m >= (int)cms ) { SetZero(); return; }
- //When f+m <=0,i.e.the value of fixed exponent cannot be taken as "fe",
- //the top figure is placed at first position figure[1].
- if(f + m <= 0) m = f ? (1 - f) : 1; //m=1 for f=0(figure[0]>0)
- } else m = 1 - f; //In the floating point mode,it sets the top figure at first position.
- if(m){ SetRdxExp(rdxExp + m); ShiftArray(m); }
-
- //It cutss down extra figures.
- if( aHead >= cms ){
- //It is better to include the rouning off, but the processing becomes complex.
- figure.clear(cms); // set figure[i] = 0 for i >= cms
- if(aTail >= cms){ // cms <= aTail <= aHead
- rdxExp = 0; SetSign(0); //All the elements of figure[] are zero.
- } else { // figure[aTail] != 0
- aHead = cms - 1u;
- while( !figure(aHead) ) aHead--; //Maybe there are zeros in intermediate region.
- }
- }
- //It cuts down the figures which has zero.
- uint fs = figure.size();
- if(IsPointFixed()){
- uint ms = ceilpow2( MaxSize() );//Not CurrentMaxSize(), because the size must be fixed.
- //If the effective figures decreased, it cuts down the size.
- if(fs > ms) figure.size(ms, 1); // cms <= ms
- } else if( 2u*(aHead+1u) <= fs ) DoCutDown();
- }
sdmrefrm.cpp : last modifiled at 2015/11/25 20:19:52(2,628 bytes)
created at 2017/10/07 10:21:15
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).